﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using LEET.Exceptions.Automation;
using LEET.CommonInterfaces.Automation;

namespace LEET.LEETCommon.AutomationAbstractions
{
    public class PathElement : IUIPathElement
    {
        public PathElement(String id)
        {
            ID = id;
            Name = "";
            Class = "";
        }

        public PathElement(String id, String name, String klass)
        {
            ID = id;
            Name = name;
            Class = klass;
        }

        public static PathElement Apply(String element)
        {

            String id = "";
            String name = "";
            String klass = "";

            Match m = Regex.Match(element, " *\\(\"?(.*?)\"?; \"?(.*?)\"?; \"?(.*?)\"?\\)");
            if (m.Success)
            {
                id = m.Groups[1].Value;
                name = m.Groups[2].Value;
                klass = m.Groups[3].Value;
            }
            else
                throw new InvalidIdentifierException();

            return new PathElement(id, name, klass);
        }

        public override string ToString()
        {
            return String.Format("({0}; {1}; {2})", ID, Name, Class);
        }

        public String ID { get; private set; }
        public String Name { get; private set; }
        public String Class { get; private set; }
    }
}
